/* AUTHORS OF LINEFOLLOW.h -> SAMUEL MCNAMARA & KILLIAN MURPHY */

/* GUARD */
#ifndef __LINEFOLLOW_H__
#define __LINEFOLLOW_H__
#include "lpc_types.h"
#include "SERIALAPI.h"

/* DECLARATIONS */

// THE CONFIGURATION STRUCT FOR LINE FOLLOWING
typedef struct {
  uint8_t FollowSpeed;
  uint8_t P_Factor;     //Perceived displacement from line
  uint8_t P_Quotient;    
  uint8_t D_Factor;     //Rate of correction
  uint8_t D_Quotient; 
} LineFollowCfg;

// CALIBRATION STATUS OF THE POLOLU LINE SENSORS
typedef enum { RAW = 0, CALIBRATED } calib_status;

// STRUCT IN WHICH TO STORE VALUES OF ALL POLOLU LINE SENSORS
typedef struct {
  calib_status status;
  uint16_t PC0;
  uint16_t PC1;
  uint16_t PC2;
  uint16_t PC3;
  uint16_t PC4;
} SensorVals;

/* EXTERNS */
extern LineFollowCfg CFG; // EXTERN FOR THE LINEFOLLOW CONFIGURATION STRUCT
extern uint8_t FOLLOWING; // FLAG TO INDICATE THAT THE POLOLU IS FOLLOWING A LINE
extern SensorVals s; // EXTERN FOR THE STRUCT CONTAINING LINE SENSOR VALUES

/* FUNCTION PROTOTYPES */
void LINE_ResetCalibration(void); // RESET POLOLU CALIBRATION BY SENDING THE
                                  // RESET BYTE OVER UART
void LINE_AutoCalibrate(void);    // TELL THE ATMEL UC TO START AUTOCALIBRATION
SensorVals* LINE_GetSensors(SensorVals *); // READ VALUES OF LINE FOLLOWING SENSORS
                                           // AND PUT THEM INTO THE POINTED TO
                                           // SENSORVALS STRUCT.

void LINE_StartFollow(LineFollowCfg *);  // TELL THE ATMEL UC TO START LINE FOLLOWING,
                                         // AND WHEN THE SENSORS NO LONGER DETECT A LINE
                                         // STOP MOVING.
void LINE_EndFollow(uint8_t); // MANUALLY STOP FOLLOWING A LINE, AND MOVE AT THE PASSED
                              // MOTOR SPEED.

#endif
